﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Parser.SyntaxTree.AutoCompleteEditHandler
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using Microsoft.Internal.Web.Utils;
using System.Collections;
using System.Collections.Generic;
using System.Web.Razor.Editor;
using System.Web.Razor.Text;
using System.Web.Razor.Tokenizer.Symbols;

namespace System.Web.Razor.Parser.SyntaxTree
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents the auto-complete editing handler class.</summary>
  public class AutoCompleteEditHandler : SpanEditHandler
  {
    /// <summary>Initializes a new instance of the <see cref="T:System.Web.Razor.Parser.SyntaxTree.AutoCompleteEditHandler" /> class.</summary>
    /// <param name="tokenizer">The tokenizer.</param>
    public AutoCompleteEditHandler(Func<string, IEnumerable<ISymbol>> tokenizer)
      : base(tokenizer)
    {
    }

    /// <summary>Initializes a new instance of the <see cref="T:System.Web.Razor.Parser.SyntaxTree.AutoCompleteEditHandler" /> class.</summary>
    /// <param name="tokenizer">The tokenizer.</param>
    /// <param name="accepted">The accepted characters.</param>
    public AutoCompleteEditHandler(
      Func<string, IEnumerable<ISymbol>> tokenizer,
      AcceptedCharacters accepted)
      : base(tokenizer, accepted)
    {
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets a value that indicates whether the auto-complete function is at the end of this span.</summary>
    /// <returns>true if the auto-complete function is at the end of this span; otherwise, false.</returns>
    public bool AutoCompleteAtEndOfSpan { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets a string value to auto-complete.</summary>
    /// <returns>A string value to auto-complete.</returns>
    public string AutoCompleteString { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates a parse result that can accept changes.</summary>
    /// <param name="target">The phase of the target.</param>
    /// <param name="normalizedChange">The normalized <see cref="T:System.Web.Razor.Text.TextChange" />.</param>
    protected override PartialParseResult CanAcceptChange(
      Span target,
      TextChange normalizedChange)
    {
      return (this.AutoCompleteAtEndOfSpan && SpanEditHandler.IsAtEndOfSpan(target, normalizedChange) || SpanEditHandler.IsAtEndOfFirstLine(target, normalizedChange)) && (normalizedChange.IsInsert && ParserHelpers.IsNewLine(normalizedChange.NewText) && this.AutoCompleteString != null) ? PartialParseResult.Rejected | PartialParseResult.AutoCompleteBlock : PartialParseResult.Rejected;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Returns the fully qualified type name of this instance.</summary>
    /// <returns>A String containing a fully qualified type name.</returns>
    public override string ToString() => base.ToString() + ",AutoComplete:[" + (this.AutoCompleteString ?? "<null>") + "]" + (this.AutoCompleteAtEndOfSpan ? ";AtEnd" : ";AtEOL");

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates whether this instance and a specified object are equal.</summary>
    /// <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.</returns>
    /// <param name="obj">The object.</param>
    public override bool Equals(object obj)
    {
      AutoCompleteEditHandler completeEditHandler = obj as AutoCompleteEditHandler;
      return base.Equals(obj) && completeEditHandler != null && string.Equals(completeEditHandler.AutoCompleteString, this.AutoCompleteString, StringComparison.Ordinal) && this.AutoCompleteAtEndOfSpan == completeEditHandler.AutoCompleteAtEndOfSpan;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Returns the hash code for this instance.</summary>
    /// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
    public override int GetHashCode() => HashCodeCombiner.Start().Add(base.GetHashCode()).Add((IEnumerable) this.AutoCompleteString).CombinedHash;
  }
}
